fix(mcp): cap tool response size to prevent OOM#66
Merged
Conversation
Several MCP tools (get_trace, get_graph_snapshot, correlated_signals, get_system_graph) marshal full DB/graph payloads with no row cap. A trace with 50k spans or a large snapshot can produce a 100 MB+ JSON response that OOMs the process and stalls every concurrent MCP call until MCP_CALL_TIMEOUT_MS fires. Adds MaxToolResponseBytes = 4 MiB enforced inside textResult() so the cap covers all 22 marshal-then-textResult sites uniformly. Over-cap responses convert to a structured error pointing operators at pagination / time-range narrowing. Tests cover: under-cap passes through, exactly-at-cap passes, over-cap errors with actionable hint, empty text is fine. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
PR D of 6. Closes the MCP OOM vector identified by codex round 1: tools that marshal full payloads (`get_trace`, `get_graph_snapshot`, `correlated_signals`, `get_system_graph`) had no byte cap. A 50k-span trace or large snapshot would produce 100MB+ JSON, OOM the process, and stall every concurrent MCP call until `MCP_CALL_TIMEOUT_MS` fires.
Test plan
🤖 Generated with Claude Code